/*
    Asignatura: Procesadores de lenguajes.
    Practica de labotario numero 9.
    Autores:
                Guillermo Garcia Juanes (Alu3889)
                Jose Antonio Hernandez Gonzalez (Alu3809)
   
   Fichero: Procesador.java
   Contenido: Procesador
*/
package pl.equipo13.p9;

import java.io.*;
import java.util.logging.*;
import org.antlr.runtime.*;

public class Procesador {

    public static void main(String[] args) {
        try {
            String rs = "";
            FileInputStream fis = new FileInputStream(args[1]);
            ANTLRInputStream input = new ANTLRInputStream(fis);
            if ("1".equals(args[0])) {
                AnalexXMLv1 lexer = new AnalexXMLv1(input);
                /*Token token = lexer.nextToken();
                while (token.getType() != Token.EOF) {
                    if (token.getChannel() != Token.HIDDEN_CHANNEL) {
                        rs += token.getText() + "\n";
                        System.out.println("Token: " + token.toString());
                    }
                    token = lexer.nextToken();
                }     
                System.out.println(rs);*/
                CommonTokenStream tokens = new CommonTokenStream(lexer);
                AnasinXMLv1 parser = new AnasinXMLv1(tokens);
                parser.entrada();
            } else if ("2".equals(args[0])) {
                AnalexXMLv2 lexer = new AnalexXMLv2(input);
                /*Token token = lexer.nextToken();
                while (token.getType() != Token.EOF) {
                    if (token.getChannel() != Token.HIDDEN_CHANNEL) {
                        rs += token.getText() + "\n";
                        System.out.println("Token: " + token.toString());
                    }
                    token = lexer.nextToken();
                }     
                System.out.println(rs);*/
                CommonTokenStream tokens = new CommonTokenStream(lexer);
                AnasinXMLv2 parser = new AnasinXMLv2(tokens);
                parser.entrada();
            }
       } catch (RecognitionException ex) {
                Logger.getLogger(Procesador.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException e) {
            System.err.println("Error al abrir el fichero.");
        } catch (IOException e) {
            System.err.println("Error al abrir el fichero.");
        }
    }
}